from django.db import models
from common.db import DbModel
# Create your models here.

class Category( DbModel):
    name = models.CharField(max_length=100,unique=True, verbose_name='商品种类名称')
    icon = models.ImageField(verbose_name='种类图标', blank=True, null=True)
    is_display = models.BooleanField(default=True, verbose_name='是否展示')
    class Meta:
        db_table = 'category'
        verbose_name = '商品种类表'
    def __str__(self):
        return self.name
class Product( DbModel):
    """商品信息模型"""
    category = models.ForeignKey(Category, on_delete=models.CASCADE, related_name='products', verbose_name='所属类别')
    name = models.CharField(max_length=255, unique=True, verbose_name='商品名称')
    description = models.TextField(blank=True, null=True, verbose_name='商品描述')
    price = models.DecimalField(max_digits=12, decimal_places=2, verbose_name='商品价格')
    stock = models.PositiveIntegerField(verbose_name='库存数量')
    image = models.ImageField(blank=True, null=True, verbose_name='商品图片')
    is_available = models.BooleanField(default=True, verbose_name='商品是否上架')
    cover_image = models.ImageField(blank=True, null=True, verbose_name='封面图片')
    title = models.CharField(max_length=225, verbose_name="商品展示标题")
    sales = models.PositiveIntegerField(default=0, verbose_name='销量')
    class Meta:
        db_table = 'products'
        verbose_name = '商品表'
        verbose_name_plural = '商品表'

    def __str__(self):
        return self.name

